<?php
/**
 * Punny - The most easy-to-use PHP MVC framework
 * 
 * Copyright (c) 2010  
 *
 * @author email :lx.xin@qq.com
 */
 class Classes extends Base {
	protected $_name='my_class';
	protected $__primary='id';

	/*
	 *获取分类列表
	 */
	 function getClasses (){
		$data=$this->fetchAll()->toArray();
		return $data;
	 }
	 /*
	  *检查分类惟一性
	  */
	  function check($name){
		  if(is_string($name)){
			$row=$this->fetchRow("1 = 1 and classname = '$name'");
			return empty($row) ? true :false ;
		  }
		  else{
			return true ;
		  }
	  }
	  /*
	   *添加分类
	   */
	   function addClass($data){
			return $this->insert($data);
	   }
	   /*
	    *根据ID,查询分类记录
		*/
		function queryClass($id){
			$db=$this->getAdapter();
			$where=$db->quoteInto('id = ?',$id);
			$row=$this->fetchRow($where)->toArray();
			return $row;
		}
		/*
		 *更新分类信息
		 */
		 function updateClass($id,$data){
			$db=$this->getAdapter();
			$where=$db->quoteInto('id = ?',$id);
			return $this->update($data,$where);
		 }
		 /*
		  *删除分类
		  */
		  function delClass($id){
			$db=$this->getAdapter();
			$where=$db->quoteInto('id = ?',$id);
			return $this->delete($where);
		  }
		  /*
		   *获取分类数
		   */
			function classNums(){
			   $num=$this->fetchAll()->count();			   
			   return $num;
			}

 }
 ?>